package com.sfpay.coreplatform.order.service.composite.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.sfpay.coreplatform.order.common.OrderResponseCode;
import com.sfpay.coreplatform.order.common.enums.PayStatus;
import com.sfpay.coreplatform.order.service.composite.common.PayContext;
import com.sfpay.coreplatform.order.service.exception.OrderServiceException;
import com.sfpay.coreplatform.order.valueobject.dto.PayRequest;
import com.sfpay.coreplatform.order.valueobject.dto.Response;
@Service
public class PayStatusHandler  extends AbstractHandler {

	private final static Logger logger = LoggerFactory
			.getLogger(PayStatusHandler.class);
	@Override
	public Response Handler(PayRequest request, PayContext payContext) throws OrderServiceException {
		 Response  response = new  Response();
		try {
			this.getPayOrderDao().updateState(payContext.getPayNo(), payContext.getAccCode()>0?PayStatus.SUCCESS:PayStatus.FAILURE,
					null);
			
			response.setReturnCode(OrderResponseCode.ORDER_RESPONSE_SUCESS);
		} catch (Exception e) {
			logger.error("methode:statusPayHandle payNo:" + payContext.getPayNo()
					+ " update status exception ", e);
			throw new OrderServiceException(
					OrderResponseCode.ORDER_DB_EXCEPTION,
					"methode:statusPayHandle payNo:" + payContext.getPayNo()
							+ " update status exception", e);
		}

		return response;

	}
	@Override
	public String getHandlerName() {
		 
		return "PayStatusHandler";
	}

}
